package com.elitesland.system.repo;

import com.elitesland.system.entity.QSysRoleDO;
import com.elitesland.system.param.SysRoleQueryParam;
import com.querydsl.core.types.ExpressionUtils;
import com.querydsl.core.types.Predicate;
import lombok.val;
import org.apache.commons.lang3.StringUtils;

/**
 * <pre>
 * [功能说明]
 * </pre>
 *
 * @author Mir
 * @date 2020/7/9
 */
public class SysRoleRepoProc {

    public static Predicate where(SysRoleQueryParam param) {
        val sysrole = QSysRoleDO.sysRoleDO;

        Predicate predicate = sysrole.isNotNull().or(sysrole.isNull());

        predicate = StringUtils.isBlank(param.getCode()) ? predicate :
                ExpressionUtils.and(predicate, sysrole.code.like("%" + param.getCode() + "%"));

        predicate = StringUtils.isBlank(param.getName()) ? predicate :
                ExpressionUtils.and(predicate, sysrole.name.like("%" + param.getName() + "%"));

        predicate = param.getEnabled() == null ? predicate :
                ExpressionUtils.and(predicate, sysrole.enabled.eq(param.getEnabled()));

        return predicate;
    }
}
